import request from '../utils/request'
import {AxiosRequestConfig, Method} from "axios";


const Http = function (url: string, method: Method, data: any = {}, config?: AxiosRequestConfig) {
    method = method.toLowerCase() as Method;
    const canSetParams = method === 'get' || method === 'delete' || method === 'head';
    return request({
        url,
        method,
        data: canSetParams ? {} : data,
        params: canSetParams ? data : {},
        ...config,
    })
}
Http.put = request.put;
Http.post = request.post;
Http.patch = request.patch;
Http.options = request.patch;
Http.get = (url: string, data = {}, config?: AxiosRequestConfig) => Http(url, 'get', data, config);
Http.head = (url: string, data = {}, config?: AxiosRequestConfig) => Http(url, 'head', data, config);
Http.delete = (url: string, data = {}, config?: AxiosRequestConfig) => Http(url, 'delete', data, config);

export default Http;
